<template>
  <div class="subject">
    <span>{{num1}}</span>
    <span>+</span>
    <span>{{num2}}</span>
    <span>=</span>
    <input v-model.number="result" type="number" :disabled="isDis"/>
    <button @click="submitFn" :disabled="isDis" >提交</button>
  </div>
</template>

<script>
export default {
      data(){
    return {
      num1:Math.floor(Math.random()*(20-0+1)+0),
      num2:Math.floor(Math.random()*(20-0+1)+0),
      result:null,
      isDis:false//禁用状态
    }
  },
  methods:{
      submitFn(){
          this.isDis=true
           let resultStr = ((this.num1 + this.num2) == this.result) ? '正确' : '错误';
      this.$emit("result", resultStr, this.index);
      }
  },
  props:["index"]
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>